<template>
	<view>
		<uni-list style="margin-top: 10px;position: relative;">
			<uni-list-item clickable @click="toCPage(0)" showArrow title="隐私政策" />
			<uni-list-item clickable @click="toCPage(1)" showArrow title="服务协议" />
			<uni-list-item clickable @click="cancellation" showArrow title="注销账号" />
		</uni-list>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				// 当前版本号
				nowVersion: "1.5.3",
				rules: {},
				formData: {},
				userInfo: {},
				userUrl: ''
			}
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo')
			this.$http('Base_Manage/Home/GetAppOperatorInfo').then(res => {
				if (res.Success) uni.setStorageSync('userInfo', res.Data)
				this.userInfo = uni.getStorageSync('userInfo')
			})

			// #ifdef APP-PLUS
			// APP 获取本地应用资源版本号
			plus.runtime.getProperty(plus.runtime.appid, (info) => {
				this.nowVersion = 'v' + info.version;
			})
			// #endif
		},
		computed: {
			progress() {
				return ((this.userInfo.StorageByte - this.userInfo.ResidueMemory) / this.userInfo.StorageByte) * 100
			},
			...mapState(['UnreadTotal'])
		},
		methods: {
			toCPage(e) {
				uni.navigateTo({
					url: '/pages/user/customerPage?Type=' + e
				})
			},
			// 注销
			cancellation() {
				uni.navigateTo({
					url: '/pages/user/cancellation'
				})
			},
			toNotice() {
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			},
			toChangePhone() {
				uni.navigateTo({
					url: '/pages/user/changePhone?phone=' + this.userInfo.Phone
				})
			},
			toMail() {
				uni.navigateTo({
					url: '/pages/Mail/Mail'
				})
			},
			// 修改个人信息
			toEditUserInfo(type) {
				console.log(type);
				let url = ''
				if (type == '姓名') url = `type=text&value=${this.userInfo.Name||''}&key=Name&title=姓名`
				else if (type == '手机号') url = `type=number&value=${this.userInfo.Phone||''}&key=Phone&title=手机号`
				else if (type == '地址') url = `type=text&value=${this.userInfo.Address||''}&key=Address&title=地址`
				else if (type == '邮箱') url = `type=text&value=${this.userInfo.Email||''}&key=Email&title=邮箱`
				uni.navigateTo({
					url: '/pages/user/editUserInfo?' + url
				})
			},
			logOut() {
				uni.removeStorageSync('loginStates');
				uni.removeStorageSync('userName');
				uni.removeStorageSync('password');
				uni.removeStorageSync('customerInfoSelect');
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			// 用户头像
			onChooseAvatar(e) {
				uni.chooseImage({
					count: 1,
					success: (rst) => {
						console.log('获取即将要裁剪的图片结果', rst)
						uni.navigateTo({
							url: '/pages/user/camera?path=' + encodeURIComponent(rst
								.tempFilePaths[0])
						})
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.uni-list-item__extra-text {
		max-width: 250px;
	}

	/deep/.uni-badge {
		min-width: 24px;
		height: 24px;
		line-height: 2;
	}

	.headerImage {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-right: 8px;

		&:active {
			background-color: #f1f1f1;
		}
	}

	.avatar-wrapper {
		margin: 10px 0 0 10px;
		border: 1px solid #ccc;
		padding: 10rpx;
		background-color: transparent;
		width: 70px;
		height: 70px;
		border-radius: 5px;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>